import { AsyncStorage } from "react-native"

const UserInfo = 'UserInfo'

export const getUser = async () => {
    try {
        const result = await AsyncStorage.getItem(UserInfo)
        if (result === null) {
            return null
        } else {
            return JSON.parse(result)
        }
    } catch (error) {
        console.log(error)
    }
}

export const saveUser = async (user) => {
    try {
        await AsyncStorage.setItem(UserInfo, JSON.stringify(user))
    } catch (error) {
        console.log(error)
    }
}

export const exitLogin = () => {
    AsyncStorage.removeItem(UserInfo, getUser)
}